package com.huan.vertxle;

import com.huan.vertxle.initialization.StartParamsInit;
import com.huan.vertxle.verticle.ScanCodeVerticle;
import com.huan.vertxle.verticle.WebRouterVerticle;
import com.huan.vertxle.verticle.WebsocketVerticle;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.Slf4JLoggerFactory;
import io.vertx.config.ConfigRetriever;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;

/**
 * vertx启动部署
 *
 * @author huan
 */
public class VertxLe extends AbstractVerticle {
  private final InternalLogger logger = Slf4JLoggerFactory.getInstance(this.getClass());

  /**
   * 打包启动会使用这个作为入口
   *
   * @throws Exception
   */
  @Override
  public void start() throws Exception {
    // 外部配置
    ConfigRetriever retriever = ConfigRetriever.create(vertx);
    retriever.getConfig().onSuccess(event -> {
      // 初始化配置参数
      StartParamsInit.initParams(event);
      // 部署verticle
      vertx.deployVerticle(WebRouterVerticle.class.getName());
      vertx.deployVerticle(WebsocketVerticle.class.getName());
      vertx.deployVerticle(ScanCodeVerticle.class.getName());
    }).onFailure(event -> {
      logger.error("启动失败:获取项目配置异常:", event.getMessage());
    });
  }
}
